/* eslint-disable camelcase */
import classnames from 'classnames'
import Icon from '@/components/Icon'
import styles from './index.module.scss'
import { ApiArticles } from '@/types/data'
import dayjs from 'dayjs'
import relativeTime from 'dayjs/plugin/relativeTime'
import 'dayjs/locale/zh-cn'
import Image from '@/components/Image'
dayjs.extend(relativeTime)
dayjs.locale('zh-cn')
type Props = {
  item:ApiArticles
}

const ArticleItem = ({ item }: Props) => {
  const { title, cover: { type, images }, aut_name, comm_count, pubdate } = item
  return (
    <div className={styles.root}>
      <div
        className={classnames(
          'article-content',
          type === 3 && 't3',
          type === 0 && 'none-mt'
        )}
      >
        <h3>{title}</h3>
        {type !== 0 && (
          <div className="article-imgs">
              {images?.map((imgSet, ind) => (
                <div className="article-img-wrapper" key={ind}>
                <Image
                    src={imgSet}
                    alt=""
                />
                </div>
              ))}
          </div>
        )}
      </div>
      <div className={classnames('article-info', type === 0 && 'none-mt')}>
        <span>{aut_name}</span>
        <span>{comm_count} 评论</span>
        <span>{dayjs(pubdate).fromNow()}</span>
        <span className="close">
          <Icon type="iconbtn_essay_close" />
        </span>
      </div>
    </div>
  )
}

export default ArticleItem
